package org.e_gold.factory;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
public class AppProperties {

	@Resource
	private Environment env;

	private static final String E_GOLD_RATE_MIN = "e_gold.rate_min";
	private static final String E_GOLD_RATE_MAX = "e_gold.rate_max";
	private static final String SAFE_MODE = "safe_mode";
	private static final String TEST_MODE = "test_mode";
	private static final String TRUE = "true";
	private static final String BET_MIN_TIME = "betMinTime";
	private static final int BET_MIN_TIME_DEFAULT = 20;
	private static final String TSA_URL = "tsa_url";
	private static final String MONITOR_URL = "monitor_url";
	private static final String MONITOR_KEY = "monitor_key";
	private static final String MONITOR_SLEEP = "monitor_sleep";
	private static final String CONFIG_URL = "config_url";
	private static final String TXT_USERNAME = "txtUsername";
	private static final String TXT_PASSWORD = "txtS3cret";


	public Float getRateMin() {

		return Float.parseFloat(env.getProperty(E_GOLD_RATE_MIN));
	}

	public Float getRateMax() {

		return Float.parseFloat(env.getProperty(E_GOLD_RATE_MAX));
	}

	public boolean isSafeMode() {

		try {
			String isSafeMode = env.getProperty(SAFE_MODE);
			if (!StringUtils.isEmpty(isSafeMode)) {
				return isSafeMode.equalsIgnoreCase(TRUE);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return true;
		}
		return true;
	}

	public boolean isTestMode(){
		return Boolean.parseBoolean((env.getProperty(TEST_MODE, TRUE)));
	}

	public String getMonitorUrl(){
		return env.getProperty(MONITOR_URL);
	}

	public String getMonitorKey(){
		return env.getProperty(MONITOR_KEY);
	}

	public int getMonitorSleep(){
		String str = env.getProperty(MONITOR_SLEEP);
		if(StringUtils.isEmpty(str)){
			return 30;
		}else{
			return Integer.parseInt(str);
		}
	}

	public String getTSAUrl(){
		return env.getProperty(TSA_URL);
	}

	public int getBetMinTime(){
		String strBetMin = env.getProperty(BET_MIN_TIME);
		if(StringUtils.isEmpty(strBetMin)){
			return BET_MIN_TIME_DEFAULT;
		}else{
			return Integer.parseInt(strBetMin);
		}
	}

	public String getConfigUrl(){
		return env.getProperty(CONFIG_URL);
	}

	public String getUserName(){
		return env.getProperty(TXT_USERNAME);
	}

	public String getPassword(){
		return env.getProperty(TXT_PASSWORD);
	}
}
